package com.iwuyc.fastexcel.ext.interfaces.impl

import com.iwuyc.fastexcel.ext.core.ExcelParser
import com.iwuyc.fastexcel.ext.data.ExcelRowInfo
import com.iwuyc.fastexcel.ext.interfaces.RowConsumer
import com.iwuyc.tools.commons.util.file.FileUtil
import lombok.extern.slf4j.Slf4j
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
import kotlin.test.Test

@Slf4j
class ExcelParserTest {
    val log: Logger = LoggerFactory.getLogger(ExcelParserTest::class.java)

    val srcDir: String = FileUtil.absoluteLocation("classpath:/food")

    @Test
    fun parse() {
        val excelFile = File(srcDir, "菜品出品部门信息.csv")
        val parser = ExcelParser(excelFile)
        val rowConsumer = object : RowConsumer {
            override fun consumer(excelRowInfo: ExcelRowInfo) {
                log.info(
                    "production_department:::${excelRowInfo.getByColumnName("production_department")};shop_code:::${
                        excelRowInfo.getByColumnName(
                            "shop_code"
                        )
                    }"
                )
            }

        }
        parser.parse(rowConsumer = rowConsumer, headRowNum = 1)
    }

    @Test
    fun parseAll() {
        val excelFile = File(srcDir, "菜品出品部门信息.csv")
        val parser = ExcelParser(excelFile)
        val rowConsumer = object : RowConsumer {
            override fun consumer(excelRowInfo: ExcelRowInfo) {
                log.info(
                    "parseAll production_department:::${excelRowInfo.getByColumnName("production_department")};shop_code:::${
                        excelRowInfo.getByColumnName(
                            "shop_code"
                        )
                    }"
                )
            }

        }
        parser.registerDefaultRowConsumer(rowConsumer)
        parser.parseAll(headRowNum = 1)

    }
}